import java.awt.*;
import javax.swing.ImageIcon;

/** Scrolling BackGround Thread*/
public class ScrollingBackGround implements Runnable {
	
	public static ScrollingBackGround BackGround;
	
	private static int ScrollingSpeed = -2;
	
	private static int FrameWidth = 800;
	private static int FrameHeight = 600;
	
	public static Image CurrentBackGround = null;
	public static Image CurrentBackGroundCopy = null;
	
	private static int BackGroundXCoordinate = 0;
	private static int BackGroundYCoordinate = 0;
	private static int BackGroundCopyXCoordinate = 0;
	private static int BackGroundCopyYCoordinate = 0;
	
	public ScrollingBackGround(){
		
		selectBackGround(1);
	}
	
	// This method let's you select the BackGround form the BackGround Folder
	public static void selectBackGround (int BackGroundNumber) {

		CurrentBackGround = loadImage("C:/DGX's/Programming Projects/Java Projects/Utilities/The Goods/BackGrounds/BackGround" + BackGroundNumber + ".jpg");

		CurrentBackGroundCopy = CurrentBackGround;
	}
	
	// Updates BackGround Coordinates
	public static void updateScrollingBackGround(){
		
	// Update the BackGround's Coordinates According to a Positive Scrolling Speed	
	if(ScrollingSpeed > 0){	
	   BackGroundXCoordinate += ScrollingSpeed;
	   BackGroundCopyXCoordinate = BackGroundXCoordinate - FrameWidth;
	if(BackGroundCopyXCoordinate >= 0) BackGroundXCoordinate = BackGroundXCoordinate - FrameWidth;
  }
	
	// Update the BackGround's Coordinates According to a Negative Scrolling Speed
	if(ScrollingSpeed < 0){	
		   BackGroundXCoordinate += ScrollingSpeed;
		   BackGroundCopyXCoordinate = BackGroundXCoordinate + FrameWidth;
		if(BackGroundCopyXCoordinate <= 0) BackGroundXCoordinate = BackGroundXCoordinate + FrameWidth;
	  }
}
	
	// Draws the BackGrounds where they belong
	public static void draw(Graphics g){
		
		g.drawImage(CurrentBackGround, BackGroundXCoordinate, BackGroundYCoordinate, 
				FrameWidth ,FrameHeight, null);
		
		g.drawImage(CurrentBackGroundCopy, BackGroundCopyXCoordinate , BackGroundCopyYCoordinate, 
				FrameWidth, FrameHeight, null);
		
	}

	private static Image loadImage(String fileName) {
		return new ImageIcon(fileName).getImage();
	}
	
	public void run(){
		
		BackGround = new ScrollingBackGround();
	}

}